/**************************************************
File: ./DataStorage/Objects.js
**************************************************/

var ObjType = {
    NONE:0,
    ROBOT:1,
    KITTY:2,
    STONE:3,
    MONSTER:4,
    BALL:5,
    DOOR:6,
    KEY:7,
    SKILL:8
};

var StoneType = {
    HARD:0,
    SOFT:1
};

var MonsterType = {
    MOVER:0,
    SHOOTER:1
};

var SkillType = {
    JUMP:0,
    SHOOT:1,
    DBL_JUMP:2,
    SPEED_UP:3
};
var inRange = function (val, beg, end) {//(,)
        return (beg < val) && (val < end);
    }
    
//******************** Object ********************
var Obj = function(_type, _subType){
    this.dae = null;
    this.pos = null;
    this.last_pos = null;
    this.rot = null;
    this.type = _type;
    this.subType = _subType;
    this.progress = 0;
    this.anims = null;
    this.kf_anims = [];


    this.isPointIn = function (pnt) {
        return (inRange(pnt.x - this.dae.position.x, -0.501, 0.501)
                && inRange(pnt.y - this.dae.position.y, -0.501, 0.501)
                && inRange(pnt.z - this.dae.position.z, -0.501, 0.501)
               );
    }
    
    this.meet = function (obj) {
        var pnt = new THREE.Vector3(0, 0, 0);
        pnt.sub(obj.dae.position, this.dae.position);
//        console.log(pnt.x, pnt.y, pnt.z);
        if (inRange(pnt.x, -0.95, 0.95)
            && inRange(pnt.y, -0.95, 0.95)
            && inRange(pnt.z, -0.95, 0.95)){
            return true;
        }
        return false;
    }
    
    return this;
};


var Objs = new Array(10);
for (var i=1; i<9; ++i){
    Objs[i] = function (_subType) {
        Obj.apply(this, [i, _subType]);
        return this;
    };
};

var Robot = Objs[ObjType.ROBOT];
Robot.prototype.jumping = 0;
Robot.prototype.max_jump = 0;
Robot.prototype.jumped = 0;
Robot.prototype.can_shoot = 0;
Robot.prototype.speed = 1;
Robot.prototype.keys = [];
Robot.prototype.hasKey = function (key) {
    for (i in this.keys){
        if (this.keys[i] == key){
            return true;
        }
    }
    return false;
};
Robot.prototype.gainKey = function (key) {
    if (this.hasKey(key)){
        return;
    }
    this.keys.push(key);
}

Objs[ObjType.MONSTER].prototype.countdown = 0;

